﻿/// <reference path="Panel.js" />
/// <reference path="../Utility/ArrayList.js" />

IM.Control.ListViewItem = function(conf) {
    IM.Control.ControlBase.apply(this, arguments);
    this.DataItem; //当前行数据项
    this.SetContent; //设置当前项内容方法
    this.Container; //当前项所在ListBox
    this.Render;
    this.Show = function() {
        var content;
        if (this.SetContent) {
            content = this.SetContent(this.DataItem);
            this.Render.html(content);
            this.Container.append(this.Render);
        }
    };

    //绑定事件
    this.Bind = function(event, fun) {
        this.Render.bind(event, fun);
    };

    this.ItemInit = function() {
        this.Render = $("<li></li>");
        this.Render.bind("dblclick", (function(obj) { return function() { if (typeof obj.OnDblClick != "undefined") { obj.OnDblClick(); } } })(this));
    };

    this.ItemInit();
};

IM.Control.ListBox = function(conf) {
    IM.Control.Panel.apply(this, arguments);
    this.Items = new IM.Utility.ArrayList(); //ListView项集合
    this.DataSource; //ListView数据源
    this.SetItemContent;
    this.DataBind = function() {
        this.Items.Clear();
        for (var i = 0; i < this.DataSource.Count(); i++) {
            this.Items.Add(new IM.Control.ListViewItem({ "DataItem": this.DataSource.Find(i), "SetContent": this.SetItemContent, Container: this.Render }));
        }
    };

    //为项元素绑定事件
    this.BindItemEvent = function(event, fun) {
        for (var i = 0; i < this.Items.Count(); i++) {
            this.Items.Find(i).Bind(event, fun);
        }
    };

    //为ListView绑定事件
    this.Bind = function(event, fun) {
        this.Render.bind(event, fun);
    };

    this.Show = function() {
        this.Render.empty();
        for (var i = 0; i < this.Items.Count(); i++) {
            this.Items.Find(i).Show();
        }
    };

    this.ListBoxInti = function() { };

    this.ListBoxInti();
};